package ie.live.byrnep.pleasesleephere.bookroom;

import ie.live.byrnep.pleasesleephere.R;
import ie.live.byrnep.pleasesleephere.base.CloudConnection;
import ie.live.byrnep.pleasesleephere.base.MessageDetails;
import ie.live.byrnep.pleasesleephere.bookroom.MainActivity.RetrieveRooms;
import android.R.bool;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class Message extends Activity{
	
	private CloudConnection cloudConnection;
	private MessageDetails messageDetails;
	private String messageTo, messageFrom, messageSubject, messageContent, user_id;
	private boolean messageSent = true;

	@Override
	protected void onCreate(final Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_message);
		cloudConnection = new CloudConnection(this);
		Bundle extras = getIntent().getExtras();
		messageTo = extras.getString("to");
		messageFrom  = extras.getString("from");
		messageSubject  = extras.getString("subject");
		messageContent = this.getString(R.string.message_content);
		
		messageDetails = new MessageDetails();
		messageDetails.setTo(messageTo);
		messageDetails.setFrom(messageFrom);
		messageDetails.setSubject(messageSubject);
				
		final TextView mesToView = (TextView) findViewById(R.id.toTextView);
		final TextView mesFromView = (TextView) findViewById(R.id.fromTextView);
		final TextView mesSubjectView = (TextView) findViewById(R.id.subjectTextView);
		final TextView mesContentView = (TextView) findViewById(R.id.messageContText);
		final Button messageButton = (Button) findViewById(R.id.sendButton);
		
		mesToView.setText(messageTo);
		mesFromView.setText(messageFrom);
		mesSubjectView.setText(messageSubject);
		mesContentView.setText(messageContent + messageFrom);
		
		messageButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(final View v) {
				messageDetails.setContent(mesContentView.getText().toString());
				messageSent = cloudConnection.sendRoomRequest(messageDetails);
				if (messageSent){
					Toast.makeText(getBaseContext(),"Message has been sent ",  
							Toast.LENGTH_LONG).show();  
				}
				else
				Toast.makeText(getBaseContext(),"Message did not send, please\n" +
												"Please try again laters",  
						Toast.LENGTH_LONG).show();  
			}
		});
		
		
		
	}
}
